package logic

import (
	"context"
	"user666/userrpc/userrpc"

	"user666/api/internal/svc"
	"user666/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UploadLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
	return &UploadLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UploadLogic) Upload(req *types.UploadRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	upload, err := l.svcCtx.UserRpc.Upload(l.ctx, &userrpc.UploadRequest{
		Username: req.Username,
		Password: req.Password,
		Newpass:  req.Newpass,
		Oldpass:  req.Oldpass,
		Code:     req.Code,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "重置密码成功",
		Code:    "200",
		Data:    upload,
	}, nil
}
